package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 添加菜品
     * @param dish
     */
    @Insert("insert dish (name, category_id, price, description, image, create_time,status, update_time,create_user,update_user)" +
            "VALUES " +
            "(#{name}, #{categoryId}, #{price}, #{description}, #{image}, #{createTime},#{status}, #{updateTime},#{createUser},#{updateUser})")
    @Options(useGeneratedKeys = true, keyProperty = "id", keyColumn = "id")
    @AutoFill(value = OperationType.INSERT)
    void insertDish(Dish dish);

    /**
     * 根据id查找菜品
     * @param id
     * @return Dish
     */
    @Select("select * from dish where id = #{id}")
    Dish getDishById(Long id);

    Page<DishVO> DishpageQuery(DishPageQueryDTO pageQueryDTO);
    @Select("select status from dish where id = #{id}")
    Long getStatusById(Long id);

    int getsetmealByDishById(Long aLong);

    void deleteDishByIds(List<Long> ids);

    void updateDish(Dish dish);

    /**
     * 动态条件查询菜品
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);
    /**
     * 根据套餐id查询菜品
     * @param setmealId
     * @return
     */
    @Select("select a.* from dish a left join setmeal_dish b on a.id = b.dish_id where b.setmeal_id = #{setmealId}")
    List<Dish> getBySetmealId(Long setmealId);
    @Update("update dish set status = #{status} where id = #{id}")
    void updateStatus(Long id, Integer status);
    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}